* Hedonic_proc.do
* 2014.05.01
* Last update 2015.07.14: merged in additional coastal controls
* Builds data set for hedonic check of instrument

capture log close
set more off
timer clear 1
timer on 1
clear
local work "/DIRECTORY"

log using "`work'/logs/Hedonic_proc.log", replace
set matsize 11000


* Reading median house values
* Made minor changes to raw file to facilitate insheet
insheet using "`work'/data/hedonic/MedHouseVals.csv", comma names clear

* Need 5-digit FIPS string for merge
tostring geoid, generate(fips)
gen fipslen = length(fips)
replace fips = "0" + fips if fipslen==4
drop if fipslen!=5 /* these are state-level medians and overall US median */
drop fipslen

* Converting median house value to numeric (force affects only 1 obs)
destring median, replace force

* Merging demographics (file includes sunset time)
merge 1:1 fips using "`work'/data/demographics/demographics_comb.dta", keep(1 3) nogenerate

* Merging distance to coast
merge 1:1 fips using "`work'/data/gis/Stata inputs/CntyCoastDistances.dta", keep(1 3) keepusing(coast_dist) nogenerate
* Merging covariates from Census Counties DB
merge m:1 fips using "`work'/data/demographics/CountiesDB_subset.dta", keep(1 3) keepusing(pop_density median_age_2010 mean_age_2010 pct_female_2010 pct_black_2010 pct_asian_2010 pct_white_2010 pct_other_2010 pct_lessthan9thgr pct_gr9to12 pct_HSgrad pct_some_college pct_BA_BS pct_grad_prof_degree occ_* naics_*) nogenerate

* Merging coastal counties
merge m:1 fips using "`work'/data/coastal_counties.dta", keep(1 3)
gen coastal = (_merge == 3)
drop _merge
gen coast = (coastal == 1 & coast_dist < 1)
gen cc = coast_dist*coast

* Saving
save "`work'/data/hedonic/Hedonic.dta", replace







timer off 1
timer list 1
capture log close



